package com.zhongkun.datahome.service.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongkun.datahome.service.domain.HouseBuildPlan;
import com.zhongkun.datahome.service.mapper.HouseBuildPlanMapper;
import com.zhongkun.datahome.service.utils.StreamUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @Author: lifengsheng
 * @Date: 2025/4/14 17:15
 * @Desc
 */
@Repository
public class HouseBuildPlanRepository extends ServiceImpl<HouseBuildPlanMapper, HouseBuildPlan> {
    public void removeByHouseIds(List<Long> houseIds) {
        if (CollectionUtils.isNotEmpty(houseIds)) {
            this.remove(new LambdaQueryWrapper<HouseBuildPlan>()
                    .in(HouseBuildPlan::getHouseId, houseIds));
        }
    }

    public List<HouseBuildPlan> listByHouseId(Long houseId) {
        return this.list(new LambdaQueryWrapper<HouseBuildPlan>()
                .eq(HouseBuildPlan::getHouseId, houseId)
                .orderByAsc(HouseBuildPlan::getBeginDate));
    }

    public Map<Long, List<HouseBuildPlan>> getMap(List<Long> houseIds) {
        if (CollectionUtils.isEmpty(houseIds)) {
            return Collections.emptyMap();
        }

        List<HouseBuildPlan> list = this.list(new LambdaQueryWrapper<HouseBuildPlan>()
                .in(HouseBuildPlan::getHouseId, houseIds));
        return StreamUtil.listGroupBy(list, HouseBuildPlan::getHouseId);
    }
}
